home *** CD-ROM | disk | FTP | other *** search
Oberon Document | 1996-01-05 | 9.0 KB | 254 lines | [oODC/obnF] |
- Documents.StdDocumentDesc
- Documents.DocumentDesc
- Containers.ViewDesc
- Views.ViewDesc
- Stores.StoreDesc
- Documents.ModelDesc
- Containers.ModelDesc
- Models.ModelDesc
- Stores.ElemDesc
- TextViews.StdViewDesc
- TextViews.ViewDesc
- TextModels.StdModelDesc
- TextModels.ModelDesc
- TextModels.AttributesDesc
- Geneva
- Geneva
- Geneva
- MODULE ObxTwins;
- IMPORT Domains, Ports, Stores, Models, Views, Controllers, Properties, TextViews;
- CONST
- minVersion = 1; maxVersion = 1; (* old version 0 ObxTwin views cannot be read anymore *)
- border = 2 * Ports.mm;
- initContents = FALSE; copyContents = TRUE;
- TYPE
- Context = POINTER TO ContextDesc;
- ContextDesc = RECORD (Models.ContextDesc)
- view: Views.View; (* contained view *)
- w, h: LONGINT; (* size of contained view *)
- domain: Domains.Domain (* domain of container model *)
- END;
- Model = POINTER TO ModelDesc;
- ModelDesc = RECORD (Models.ModelDesc)
- width, topHeight, botHeight: LONGINT;
- top, bottom: Context
- END;
- View = POINTER TO ViewDesc;
- ViewDesc = RECORD (Views.ViewDesc)
- model: Model;
- focus: Context (* current focus; either model.top or model.bottom *)
- END;
- (* Context *)
- PROCEDURE (c: Context) ThisDomain (): Domains.Domain;
- BEGIN
- RETURN c.domain
- END ThisDomain;
- PROCEDURE (c: Context) GetSize (VAR w, h: LONGINT);
- BEGIN
- w := c.w - border;
- h := c.h - border
- END GetSize;
- PROCEDURE (c: Context) Normalize (): BOOLEAN;
- BEGIN
- RETURN TRUE (* current scroll positions won't be stored, and scrolling isn't undoable *)
- END Normalize;
- PROCEDURE CopyOf (source: Context; copyContents: BOOLEAN): Context; (* make a deep copy of a context *)
- VAR c: Context; st: Stores.Store; v: Views.View; m, n: Models.Model;
- BEGIN
- NEW(c);
- st := Stores.Clone(source.view); v := st(Views.View);
- m := source.view.ThisModel();
- IF m # NIL THEN
- st := Stores.Clone(m); n := st(Models.Model);
- IF copyContents THEN n.CopyAllFrom(m) ELSE n.InitFrom(m) END;
- v.InitModel(n)
- END;
- v.CopyFrom(source.view);
- c.view := v; c.w := source.w; c.h := source.h; v.InitContext(c);
- RETURN c
- END CopyOf;
- PROCEDURE InitDomain (c: Context; d: Domains.Domain);
- BEGIN
- c.domain := d; c.view.InitDomain(d)
- END InitDomain;
- PROCEDURE NewContext (v: Views.View; w, h: LONGINT): Context;
- VAR c: Context;
- BEGIN
- NEW(c);
- c.view := v; c.w := w; c.h := h; v.InitContext(c);
- RETURN c
- END NewContext;
- (* Model *)
- PROCEDURE (m: Model) Internalize (VAR rd: Stores.Reader);
- VAR thisVersion: SHORTINT; v: Views.View;
- BEGIN
- m.Internalize^(rd);
- IF ~rd.cancelled THEN
- rd.ReadVersion(minVersion, maxVersion, thisVersion);
- IF~ rd.cancelled THEN
- rd.ReadLInt(m.width);
- rd.ReadLInt(m.topHeight);
- rd.ReadLInt(m.botHeight);
- Views.ReadView(rd, v); m.top := NewContext(v, m.width, m.topHeight);
- Views.ReadView(rd, v); m.bottom := NewContext(v, m.width, m.botHeight)
- END
- END
- END Internalize;
- PROCEDURE (m: Model) Externalize (VAR wr: Stores.Writer);
- BEGIN
- m.Externalize^(wr);
- wr.WriteVersion(maxVersion);
- wr.WriteLInt(m.width);
- wr.WriteLInt(m.topHeight);
- wr.WriteLInt(m.botHeight);
- Views.WriteView(wr, m.top.view);
- Views.WriteView(wr, m.bottom.view)
- END Externalize;
- PROCEDURE (m: Model) CopyAllFrom (source: Models.Model);
- BEGIN
- WITH source: Model DO
- m.width := source.width;
- m.topHeight := source.topHeight;
- m.botHeight := source.botHeight;
- m.top := CopyOf(source.top, copyContents);
- m.bottom := CopyOf(source.bottom, copyContents)
- END
- END CopyAllFrom;
- PROCEDURE (m: Model) InitFrom (source: Models.Model);
- BEGIN
- WITH source: Model DO
- m.width := source.width;
- m.topHeight := source.topHeight;
- m.botHeight := source.botHeight;
- m.top := CopyOf(source.top, initContents);
- m.bottom := CopyOf(source.bottom, initContents)
- END
- END InitFrom;
- PROCEDURE (m: Model) InitDomain (d: Domains.Domain);
- BEGIN
- m.InitDomain^(d);
- InitDomain(m.top, d);
- InitDomain(m.bottom, d)
- END InitDomain;
- (* View *)
- PROCEDURE (v: View) InitModel (m: Models.Model);
- BEGIN
- ASSERT((v.model = NIL) OR (m = v.model), 20);
- ASSERT(m # NIL, 21); ASSERT(m IS Model, 23);
- v.model := m(Model);
- v.focus := v.model.bottom
- END InitModel;
- PROCEDURE (v: View) ThisModel (): Model;
- BEGIN
- RETURN v.model
- END ThisModel;
- PROCEDURE (v: View) Internalize (VAR rd: Stores.Reader);
- VAR thisVersion: SHORTINT; s: Stores.Store;
- BEGIN
- v.Internalize^(rd);
- IF ~rd.cancelled THEN
- rd.ReadVersion(minVersion, maxVersion, thisVersion);
- IF ~rd.cancelled THEN
- rd.ReadStore(s); ASSERT(s # NIL, 100);
- v.InitModel(s(Model))
- END
- END
- END Internalize;
- PROCEDURE (v: View) Externalize (VAR wr: Stores.Writer);
- BEGIN
- v.Externalize^(wr);
- wr.WriteVersion(maxVersion);
- wr.WriteStore(v.model)
- END Externalize;
- PROCEDURE (v: View) Restore (f: Views.Frame; l, t, r, b: LONGINT);
- VAR m: Model; w: Views.View;
- BEGIN
- m := v.model;
- f.DrawLine(0, m.topHeight, m.width, m.topHeight, f.dot, Ports.black);
- (* install the subframes for the subviews *)
- w := m.top.view; Views.InstallFrame(f, w, Ports.mm, Ports.mm, 0, v.focus.view = w);
- w := m.bottom.view; Views.InstallFrame(f, w, Ports.mm, Ports.mm + m.topHeight, 1, v.focus.view = w)
- END Restore;
- PROCEDURE SetFocus (v: Views.View; x, y: LONGINT): BOOLEAN;
- VAR p: Properties.FocusPref;
- BEGIN (* determine whether v should be focused when the mouse is clicked at (x, y) in v *)
- p.hotFocus := FALSE;
- p.atLocation := TRUE; p.x := x; p.y := y;
- p.setFocus := FALSE; p.selectOnFocus := FALSE;
- v.HandlePropMsg(p);
- RETURN p.setFocus
- END SetFocus;
- PROCEDURE (v: View) HandleCtrlMsg (f: Views.Frame; VAR msg: Views.CtrlMessage;
- VAR focus: Views.View);
- VAR g: Views.Frame; m: Model; newFocus: Context; mMsg: Controllers.MarkMsg;
- BEGIN
- m := v.model;
- WITH msg: Controllers.CursorMessage DO
- IF msg.y >= m.topHeight THEN newFocus := m.bottom ELSE newFocus := m.top END;
- focus := newFocus.view;
- IF (newFocus # v.focus) & ((msg IS Controllers.TrackMsg) OR (msg IS Controllers.DropMsg)) &
- SetFocus(focus, msg.x, msg.y) THEN
- (* remove marks in old focus *)
- mMsg.show := FALSE;
- g := Views.ThisFrame(f, v.focus.view); IF g # NIL THEN Views.ForwardCtrlMsg(g, mMsg) END;
- v.focus := newFocus; (* set new focus *)
- (* set marks in new focus *)
- mMsg.show := TRUE;
- g := Views.ThisFrame(f, v.focus.view); IF g # NIL THEN Views.ForwardCtrlMsg(g, mMsg) END
- END
- (* the following scrolling-oriented messages are always sent to bottom view, independent of focus *)
- | msg: Controllers.PollSectionMsg DO
- focus := m.bottom.view
- | msg: Controllers.ScrollMsg DO
- focus := m.bottom.view
- | msg: Controllers.PageMsg DO
- focus := m.bottom.view
- ELSE (* all other messages are sent to the focus, however *)
- focus := v.focus.view
- END
- (* the assignment to focus signals that the view v wants to forward the message to the
- corresponding embedded view *)
- END HandleCtrlMsg;
- PROCEDURE (v: View) HandlePropMsg (VAR msg: Views.PropMessage);
- BEGIN
- WITH msg: Properties.SizePref DO
- msg.w := v.model.width; msg.h := v.model.topHeight + v.model.botHeight
- | msg: Properties.ResizePref DO
- msg.fixed := TRUE
- ELSE
- Views.HandlePropMsg(v.model.bottom.view, msg)
- END
- END HandlePropMsg;
- PROCEDURE NewTwin* (width, topHeight, botHeight: LONGINT; top, bottom: Views.View): Views.View;
- VAR m: Model; v: View;
- BEGIN
- NEW(m);
- m.width := width; m.topHeight := topHeight; m.botHeight := botHeight;
- m.top := NewContext(top, width, topHeight);
- m.bottom := NewContext(bottom, width, botHeight);
- NEW(v); v.InitModel(m);
- RETURN v
- END NewTwin;
- (* example twin view with two embedded text views *)
- PROCEDURE New* (): Views.View;
- CONST width = 160 * Ports.mm; topHeight = 30 * Ports.mm; botHeight = 500 * Ports.mm;
- BEGIN
- RETURN NewTwin(width, topHeight, botHeight,TextViews.dir.StdNew(), TextViews.dir.StdNew())
- END New;
- PROCEDURE Deposit*;
- BEGIN
- Views.Deposit(New())
- END Deposit;
- END ObxTwins.
- TextControllers.StdCtrlDesc
- TextControllers.ControllerDesc
- Containers.ControllerDesc
- Controllers.ControllerDesc
- TextRulers.StdRulerDesc
- TextRulers.RulerDesc
- TextRulers.StdStyleDesc
- TextRulers.StyleDesc
- TextRulers.AttributesDesc
- Arial
- Documents.ControllerDesc
-